home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!news
- From: jhewett@ix.netcom.com (Jerry Hewett)
- Newsgroups: comp.lang.c++
- Subject: Re: Did I Miss Something?
- Date: Thu, 04 Apr 96 18:58:38 GMT
- Organization: Netcom
- Message-ID: <N.040496.105838.83@ix.netcom.com>
- References: <N.040396.105136.51@ix.netcom.com>
- <3163AA77.5901@cmt.lpr.mail.carel.fi>
- NNTP-Posting-Host: tem-ca1-08.ix.netcom.com
- X-NETCOM-Date: Thu Apr 04 12:58:06 PM CST 1996
- X-Newsreader: Quarterdeck Message Center [2.00]
-
- Ari Lukumies <aril@cmt.lpr.mail.carel.fi> replies:
-
- >> Below is the constructor for "box". The object doesn't exist until the
- >> constructor creates it. Since a pointer to a "known" fixed-length string
- >> is being passed to the constructor, the compiler determines the amount of
- >> memory required to store the string "small box ", allocates space for it
- >> in the object, and copies it into this space.
- >>
- >> Once the object passes out of scope this "magically" created chunk of
- >> memory allocation disappears along with the object... (???)
-
- > Not quite - compiler does not determine and allocate anything. main() calls
- > the constructor with the parameter "small box". This is a constant character
- > string (read: array ending with a '\0') that is stored somewhere in the
- > memory. The assignment line_of_text = input_line simply assigns the address
- > of this string to line_of_text, without allocating any memory. Similarly,
- >there's no destructor, so the memory is not freed, and of course should not
- > be, because it was not allocated by the ctor in the first place.
-
- I've been reading through all of my reference books on C++ since I posted this
- yesterday (see my previous reply to Keith Whittingham), and discovered another
- major hole in my understanding of C/C++.
-
- Due to my (obviously! :-) less than complete understanding of pointers and
- string storage I was guessing that the creation of the box::small object was
- performing some kind of "copy constructor" behavior -- a bitwise copy of the
- object's data when the constructor was called. This new behavior in C++ (new
- to me, at least) of treating "char *" as if it were defined as "const char *",
- along with the creation of a string table entry, is something I should have
- apparently picked up while learning C, and is (?) covered by scope resolution.
-
- > To make the ctor allocate some memory [...]
-
- Errr.... "ctor"? What's a "ctor"?
-
- Jerry ("An Old Dog Learning New Tricks") H.
-
-
-